package com.mcxx.common.service.impl;

import com.mcxx.modules.miniSalvation.fundpay.service.read.FundPayFamilyReadService;
import com.mcxx.modules.statistics.entity.MemberInfoEntity;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;

import static java.util.stream.Collectors.toList;


public class FundPayBizVerifyUtil {


    public static String verifyBizIsDone(List<String> ids, FundPayFamilyReadService service) {

        List<String> idCards = service.getDoingOrderBySourceIds(ids);


        List<String> hisDead = new ArrayList<>();
        if (idCards.size() > 0)
            hisDead = service.getHistoryNoDeadMember(idCards);

        List<String> finalHisDead = hisDead;
        List<String> curDead =
                idCards.stream().filter(item -> !new ArrayList<>(finalHisDead).contains(item)).collect(toList());

        if (!curDead.isEmpty()) {
            List<MemberInfoEntity> list = service.selectDeadMemberInfo(curDead);
            Map<String, List<MemberInfoEntity>> member = list.stream()
                    .collect(Collectors.groupingBy(e-> "【" + e.getAreaName() + ":户主身份证:" + e.getMasterIdCard() + "】"));
            Set<String> set = member.keySet();
            String cards = set.stream().map(String::valueOf).collect(Collectors.joining(";"));
            return  "以下家庭中" + cards + "存在已死亡成员且业务未办结，无法生成名册，请先办结业务！";
        }
        return null;
    }
}
